import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:management/app/cons.dart';

class SetRegistrationPoint extends StatelessWidget {
  SetRegistrationPoint({Key? key}) : super(key: key);

  final TextEditingController _registrationPointEditingController =
      TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _buildAppBar(),
      body: _buildBody(context),
    );
  }

  _buildAppBar() => AppBar(
        title: Text(
          "登记点",
          style: TextStyle(fontSize: 30),
        ),
        centerTitle: true,
      );

  _buildBody(context) => Container(
        padding: EdgeInsets.all(20),
        child: Column(
          children: [
            ListTile(
              title: Row(
                children: [
                  Text(
                    "填入登记点",
                    style: TextStyle(fontSize: 30),
                  ),
                  SizedBox(
                    width: 200,
                  ),
                  Container(
                    width: 300,
                    child: TextField(
                      controller: _registrationPointEditingController,
                      style: TextStyle(fontSize: 25),
                      decoration: InputDecoration(
                        hintText: SpUtil.getString(
                            Strings.sp_key_registrationPoint,
                            defValue:
                                Strings.sp_defaultValue_registrationPoint),
                      ),
                    ),
                  )
                ],
              ),
            ),
            SizedBox(
              height: 100,
            ),
            MaterialButton(
              minWidth: 200,
              height: 50,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.horizontal(
                    left: Radius.circular(50), right: Radius.circular(50)),
              ),
              color: Colors.blue,
              child: Text(
                "确定修改",
                style: TextStyle(color: Colors.white, fontSize: 30),
              ),
              onPressed: () {
                var text = _registrationPointEditingController.text;
                if (!TextUtil.isEmpty(text)) {
                  SpUtil.putString(Strings.sp_key_registrationPoint, text);
                  SystemChrome.setEnabledSystemUIOverlays([]);
                  Navigator.pop(context);
                } else {
                  Fluttertoast.showToast(msg: "登记点不能为空");
                }
              },
            ),
          ],
        ),
      );
}
